<template>
  <view class="user-card">
    <view class="card-content">
      <view class="avatar-section">
        <image 
          class="avatar-image" 
          :src="avatarUrl" 
          mode="aspectFill"
          @error="handleAvatarError"
        />
      </view>
      
      <view class="user-info">
        <text class="user-name">{{ displayName }}</text>
        <text class="user-role">{{ roleText }}</text>
        <text class="user-dept">{{ deptText }}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'UserCard',
  props: {
    user: {
      type: Object,
      default: () => ({})
    },
    editable: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    avatarUrl() {
      return this.user.avatar || this.user.avatarUrl || '/static/logo.png'
    },
    displayName() {
      return this.user.nickname 
    },
    roleText() {
      return this.user.roles?.join(', ') || this.user.roleName || '普通用户'
    },
    deptText() {
      return this.user.dept?.deptName || this.user.deptName || '未分配部门'
    }
  },
  methods: {
    handleAvatarError() {
      console.warn('头像加载失败，使用默认头像')
    }
  }
}
</script>

<style lang="scss" scoped>
.user-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 20rpx;
  padding: 40rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
}

.card-content {
  display: flex;
  align-items: center;
  gap: 30rpx;
}

.avatar-section {
  position: relative;
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  overflow: hidden;
  background-color: #fff;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
}

.avatar-image {
  width: 100%;
  height: 100%;
}

.user-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}

.user-name {
  font-size: 36rpx;
  font-weight: bold;
  color: #fff;
  margin-bottom: 8rpx;
}

.user-role {
  font-size: 28rpx;
  color: rgba(255, 255, 255, 0.9);
}

.user-dept {
  font-size: 26rpx;
  color: rgba(255, 255, 255, 0.8);
}

@media (max-width: 750px) {
  .user-card {
    padding: 32rpx;
  }
  
  .avatar-section {
    width: 100rpx;
    height: 100rpx;
  }
  
  .user-name {
    font-size: 32rpx;
  }
  
  .user-role {
    font-size: 26rpx;
  }
  
  .user-dept {
    font-size: 24rpx;
  }
}
</style>